//
//  BLMeet_Cell_DetailHeader.m
//  Byelone
//
//  Created by 乔小乔 on 2020/12/17.
//

#import "BLMeet_Cell_DetailHeader.h"
#import "YJBannerView.h"
#import "YJHollowPageControl.h"
#import "BLMeet_Cell_DetailBanner.h"
@interface BLMeet_Cell_DetailHeader ()<YJBannerViewDataSource, YJBannerViewDelegate>
@property (nonatomic, strong) YJBannerView *bannerView;
@property (nonatomic, strong) NSArray *bannerArray;//banner数据源
@end
@implementation BLMeet_Cell_DetailHeader

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.viewHead addSubview:self.bannerView];
    self.viewInfo.layer.cornerRadius = 6;
    [self.viewInfo setShadowRadius:16 color:BL_COLOR_PURPLE_L(0.12) offset:CGSizeMake(0, 4) opacity:1];
    self.imgHeadPic.layer.cornerRadius = 30;
    self.imgHeadPic.layer.borderColor = [UIColor whiteColor].CGColor;
    self.imgHeadPic.layer.borderWidth = 1;
    [self.imgHeadPic setShadowRadius:16 color:BL_COLOR_PURPLE_L(0.12) offset:CGSizeMake(0, 4) opacity:1];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
- (void)reloadWithData:(NSArray *)array withData:(BLMeetDetailModel *)data{
    self.bannerArray = array;
    if (self.isShouldEdit) {
        self.btnEdit.hidden = NO;
       
        BLInfoUserInfo *userInfo = [BLUserManager shareUser].userInfo;
        BLInfoBaseInfo *baseInfo = [BLUserManager shareUser].baseInfo;
        BLInfoDetailInfo *detailInfo = [BLUserManager shareUser].detailInfo;
        
        [self.imgHeadPic sd_setImageWithURL:[NSURL URLWithString:userInfo.picture?:@""]];
        self.labelName.text = userInfo.nickName;
        if ([NSString blIsBlankString:userInfo.nickName]) {
            self.labelName.text = @" ";
        }
        
        NSString *strDesc = [NSString stringWithFormat:@"%@cm | %@kg",baseInfo.height,baseInfo.weight];
        if (![NSString blIsBlankString:detailInfo.yearIncomeName]) {
            strDesc = [NSString stringWithFormat:@"%@ | %@",strDesc,detailInfo.yearIncomeName];
        }
        self.labelDesc.text = strDesc;
        
        self.labelPosition.text = [NSString stringWithFormat:@"%@-%@",detailInfo.industryName?:@"",detailInfo.positionName?:@""];
        self.labelSchool.text = [NSString stringWithFormat:@"%@-%@",detailInfo.school?:@"",detailInfo.major?:@""];
        self.labelAmountt.text = detailInfo.yearIncomeName?:@"";
        //    标签
        [self.viewTips.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        NSArray *arrayTip = @[@{@"title":[NSString stringWithFormat:@"%ld",baseInfo.age],@"img":[UIImage imageNamed:baseInfo.gender==1?@"common_boy":@"common_girl"],@"color":baseInfo.gender==1?@"#6891F7":@"#FD5680"},@{@"title":[NSString stringWithFormat:@"%@-%@",baseInfo.livingAreaName,baseInfo.livingCityName],@"img":[UIImage imageNamed:@"common_location"],@"color":@"#56BDFF"},@{@"title":baseInfo.marryStatusName,@"color":@"#6C72F5"}];
        CGFloat spaceLeft = 0;
        for (int i=0; i<arrayTip.count; i++) {
            NSDictionary *dict = arrayTip[i];
            UIView *view = [BLCommonTool createTip:dict[@"img"] title:dict[@"title"] color:[UIColor chColorWithHexString:dict[@"color"]] point:CGPointMake(spaceLeft, 0)];
            [self.viewTips addSubview:view];
            spaceLeft = spaceLeft + view.frame.size.width+6;
        }
        
    }else{
        if (data) {            
            self.btnEdit.hidden = YES;
            self.btnCamara.hidden = YES;
            [self.imgHeadPic sd_setImageWithURL:[NSURL URLWithString:data.userHomeBaseVo.picture?:@""]];
            self.labelName.text = data.userHomeBaseVo.nickname;
            if ([NSString blIsBlankString:data.userHomeBaseVo.nickname]) {
                self.labelName.text = @" ";
            }
            
            NSString *strDesc = [NSString stringWithFormat:@"%@cm | %@kg",data.userHomeBaseVo.height,data.userHomeBaseVo.weight];
            if (![NSString blIsBlankString:data.userHomeDetailVo.yearIncomeName]) {
                strDesc = [NSString stringWithFormat:@"%@ | %@",strDesc,data.userHomeDetailVo.yearIncomeName];
            }
            self.labelDesc.text = strDesc;
            
            self.labelPosition.text = [NSString stringWithFormat:@"%@-%@",data.userHomeDetailVo.industryName?:@"",data.userHomeDetailVo.positionName?:@""];
            self.labelSchool.text = [NSString stringWithFormat:@"%@-%@",data.userHomeDetailVo.school?:@"",data.userHomeDetailVo.major?:@""];
            self.labelAmountt.text = data.userHomeDetailVo.yearIncomeName?:@"";
            //    标签
            [self.viewTips.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            NSArray *arrayTip = @[@{@"title":data.userHomeBaseVo.age,@"img":[UIImage imageNamed:data.userHomeBaseVo.gender.integerValue==1?@"common_boy":@"common_girl"],@"color":data.userHomeBaseVo.gender.integerValue==1?@"#6891F7":@"#FD5680"},@{@"title":[NSString stringWithFormat:@"%@-%@",data.userHomeBaseVo.livingAreaName,data.userHomeBaseVo.livingCityName],@"img":[UIImage imageNamed:@"common_location"],@"color":@"#56BDFF"},@{@"title":data.userHomeBaseVo.marryStatusName,@"color":@"#6C72F5"}];
            CGFloat spaceLeft = 0;
            for (int i=0; i<arrayTip.count; i++) {
                NSDictionary *dict = arrayTip[i];
                UIView *view = [BLCommonTool createTip:dict[@"img"] title:dict[@"title"] color:[UIColor chColorWithHexString:dict[@"color"]] point:CGPointMake(spaceLeft, 0)];
                [self.viewTips addSubview:view];
                spaceLeft = spaceLeft + view.frame.size.width+6;
            }
            
            [self.viewDesc.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            NSMutableArray *arraydesc = [NSMutableArray new];
            if (data.highCredit) {
                [arraydesc addObject:@{@"title":@"高信用",@"img":[UIImage imageNamed:@"meet_credit"],@"color":@"#56BDFF"}];
            }
            if (data.active) {
                [arraydesc addObject:@{@"title":@"高活跃",@"img":[UIImage imageNamed:@"meet_active"],@"color":@"#6C72F5"}];
            }
            if (data.highCharm) {
                [arraydesc addObject:@{@"title":@"高魅力",@"img":[UIImage imageNamed:@"meet_charm"],@"color":@"#FD5680"}];
            }
            
            CGFloat descLeft = 0;
            for (int i=0; i<arraydesc.count; i++) {
                NSDictionary *dict = arraydesc[i];
                UIView *view = [BLCommonTool createDesc:dict[@"img"] title:dict[@"title"] color:[UIColor chColorWithHexString:dict[@"color"]] point:CGPointMake(descLeft, 0)];
                [self.viewDesc addSubview:view];
                descLeft = descLeft + view.frame.size.width+6;
            }
        }
    }
}
- (IBAction)clickEdit:(UIButton *)sender {
    //    101编辑,102保存
    if (sender.tag == 101) {
//        self.btnEdit.hidden = YES;
//        self.btnEnd.hidden = NO;
    }else if (sender.tag == 102){
//        self.btnEdit.hidden = NO;
//        self.btnEnd.hidden = YES;
    }
    if (self.editBlock) {
        self.editBlock(sender.tag);
    }
}
- (IBAction)clickCamara:(id)sender {
    if (self.camaraBlock) {
        self.camaraBlock();
    }
}

-(void)adjustBannerViewWhenCardScreen{
    [self.bannerView adjustBannerViewWhenCardScreen];
}
#pragma mark - YJBannerDelegate

- (NSArray *)bannerViewImages:(YJBannerView *)bannerView{
    return self.bannerArray;
}

- (NSArray *)bannerViewRegistCustomCellClass:(YJBannerView *)bannerView{
    
    return @[[BLMeet_Cell_DetailBanner class]];
    
}
// 自定义cell的复用标识
- (Class)bannerView:(YJBannerView *)bannerView reuseIdentifierForIndex:(NSInteger)index{
    
    return [BLMeet_Cell_DetailBanner class];
}

- (UICollectionViewCell *)bannerView:(YJBannerView *)bannerView customCell:(UICollectionViewCell *)customCell index:(NSInteger)index{
    NSString *url = self.bannerArray[index];
    BLMeet_Cell_DetailBanner *cell = (BLMeet_Cell_DetailBanner*)customCell;
    [cell reloadWithUrl:url?:@""];
    return cell;
}

- (CGFloat)bannerViewFooterViewHeight:(YJBannerView *)bannerView{
    
    return  0.01;
}

- (void)bannerView:(YJBannerView *)bannerView didSelectItemAtIndex:(NSInteger)index{
    
}
#pragma mark - get&&set
- (YJBannerView *)bannerView{
    if (!_bannerView) {
        _bannerView = [YJBannerView bannerViewWithFrame:CGRectMake(0, 0, BL_WINDOW_WIDTH, BL_WINDOW_WIDTH*40/75) dataSource:self delegate:self emptyImage:[UIImage imageNamed:@"defaultImage"] placeholderImage:[UIImage imageNamed:@"defaultImage"] selectorString:@"sd_setImageWithURL:placeholderImage:"];
        _bannerView.pageControlStyle = PageControlCustom;
        _bannerView.pageControlDotSize = CGSizeMake(10, 4);
        _bannerView.customPageControlHighlightImage = [UIImage imageNamed:@"pageControlS"];
        _bannerView.customPageControlNormalImage = [UIImage imageNamed:@"pageControlN"];
        _bannerView.pageControlPadding = 2;
        _bannerView.pageControlAliment = PageControlAlimentCenter;
        _bannerView.pageControlBottomMargin = 70;
        _bannerView.autoDuration = 5;
    }
    return _bannerView;
}

- (void)setBannerArray:(NSArray *)bannerArray{
    _bannerArray = bannerArray;
    [self.bannerView reloadData];
//    if (_defoultImg) {
//        _defoultImg.hidden = YES;
//    }
}
@end
